﻿/**
 * RippleBlocksFilter
 *
 * @author		Allen Chou
 * @version		1.0.1 (last update: Nov 16 2008)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */

 package idv.cjcat.filters {
	import flash.display.Shader;
	import flash.filters.ShaderFilter;
	import flash.utils.ByteArray;
	
	import idv.cjcat.utils.ByteArrayCodec;

	/**
	 * A RippleBlocks filter.
	 */
	public class RippleBlocksFilter extends ShaderFilter {
		
		public function RippleBlocksFilter(amount:Number = 2, angle:Number = 0) {
			if (pbjByteArray == null) pbjByteArray = ByteArrayCodec.decode(pbjString);
			
			this.shader = new Shader(pbjByteArray);
		}
		
		/**
		 * The amplitude of horizontal ripples.
		 */
		public function get amplitudeX():Number { return shader.data.amplitude.value[0]; }
		public function set amplitudeX(value:Number):void { shader.data.amplitude.value[0] = value; }
		/**
		 * The amplitude of vertical ripples.
		 */
		public function get amplitudeY():Number { return shader.data.amplitude.value[1]; }
		public function set amplitudeY(value:Number):void { shader.data.amplitude.value[1] = value; }
		
		/**
		 * The phase of horizontal ripples.
		 */
		public function get phaseX():Number { return shader.data.phase.value[0]; }
		public function set phaseX(value:Number):void { shader.data.phase.value[0] = value; }
		/**
		 * The phase of vertical ripples.
		 */
		public function get phaseY():Number { return shader.data.phase.value[1]; }
		public function set phaseY(value:Number):void { shader.data.phase.value[1] = value; }
		
		/**
		 * The wavelength of horizontal ripples.
		 */
		public function get wavelengthX():Number { return shader.data.wavelength.value[0]; }
		public function set wavelengthX(value:Number):void { shader.data.wavelength.value[0] = value; }
		/**
		 * The wavelength of vertical ripples.
		 */
		public function get wavelengthY():Number { return shader.data.wavelength.value[1]; }
		public function set wavelengthY(value:Number):void { shader.data.wavelength.value[1] = value; }
		
		private static const pbjString:String = "2581808080248C80D2E9F0F0ECE5C2ECEFE3EBF3208CEEE1EDE5F3F0E1E3E580C1ECECE5EEA0C3E8EFF580208CF6E5EEE4EFF280802088F6E5F2F3E9EFEE808180208CE4E5F3E3F2E9F0F4E9EFEE80E2EFF8ADF3E8E1F0E5E4A0F2E9F0F0ECE5A0E5E6E6E5E3F48021818280808CDFCFF5F4C3EFEFF2E480218182808083E1EDF0ECE9F4F5E4E5802282EDE9EED6E1ECF5E58080808080808080802282EDE1F8D6E1ECF5E580C2488080C24880802282E4E5E6E1F5ECF4D6E1ECF5E580C1208080C120808021818281808CF7E1F6E5ECE5EEE7F4E8802282EDE9EED6E1ECF5E580BF008080BF0080802282EDE1F8D6E1ECF5E580C2488080C24880802282E4E5E6E1F5ECF4D6E1ECF5E580C1A08080C1A08080218182818083F0E8E1F3E5802282EDE9EED6E1ECF5E58080808080808080802282EDE1F8D6E1ECF5E580C0498ED6C0498ED62282E4E5E6E1F5ECF4D6E1ECF5E5808080808080808080238084F3F2E38021828482808FE4F3F4809D83804180809080848380A081808080838380A0838080809D8380908380008081838090818000808C8380A0838040809D8380908080008083838090838000808183800083804080848380A08180C080838380A08380C0809D8380908380008081838090818040808D8380A0838040809D838090808040808383809083800080818380C0838040809D8380A0838080809D8380908380C080B1848071838030809D82807384809B80";
		private static var   pbjByteArray:ByteArray = null;
	}
}